﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Logger;

namespace Cofe.Data
{
    //public class Log
    //{
    //    public int? Id { get; set; }
    //    public DateTime Time { get; set; }
    //    public string Message { get; set; }
    //    public int Category { get; set; }
    //    public int Priority { get; set; }
    //}

    public class CofeSystemEventLog
    {
        public int? Id { get; set; }
        public string UserId { get; set; }
        public string Sender { get; set; }
        public DateTime Time { get; set; }
        public string VolumeId { get; protected set; }
        public Guid? EntryId { get; protected set; }
        public /*ModifiedAction*/ Int16 ChangeType { get; protected set; }
        public ModifiedAction ChangeTypeTyped { get { return (ModifiedAction)ChangeType; } }

        public int? ActionCalled { get; protected set; }

        public virtual string EntryParsePath { get; protected set; }
        public virtual bool IsFolder { get; protected set; }

        public static CofeSystemEventLog FroEventLog(IEventLog<CofeSystemEventArgs> eventLog, Guid entryId)
        {
            var retVal = new CofeSystemEventLog()
            {
                UserId = eventLog.UserId,
                Sender = eventLog.Sender,
                Time = eventLog.UtcTime,
                VolumeId = eventLog.EventArgs.VolumeId,
                ChangeType = (Int16)eventLog.EventArgs.ChangeType,
                ActionCalled = eventLog.EventArgs.ActionId,
                EntryParsePath = eventLog.EventArgs.FullParsePath,                
                IsFolder = eventLog.EventArgs.IsFolder
            };

            if (entryId != Guid.Empty)
                retVal.EntryId = entryId;

            return retVal;

        }
    }
}
